﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Honestysoft.BaseObject;
using System.Data;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.WebUI.Module.Reports.JSON
{
    /// <summary>
    /// GetOther 的摘要说明
    /// </summary>
    public class GetOther : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string id = context.Request.Params["ID"];
            QueryParameters query = new QueryParameters();
            query.Add("WeekReportID", id, QueryParameters.OperatorType.Equal);
            OrderParameters order = new OrderParameters();
            order.Add("SortNo");
            try
            {
                DataTable dt = new BaseBusinessLogic<Bu_WeekReport_Other>("").GetTable(query, order);
                string json = "{\"total\":" + dt.Rows.Count + ",\"rows\":[";
                foreach (DataRow dr in dt.Rows)
                {
                    json += "{";
                    json += "\"ID\":\"" + dr["ID"].ToString() + "\",";
                    json += "\"SortNo\":\"" + dr["SortNo"].ToString() + "\",";
                    json += "\"Description\":\"" + dr["Description"].ToString() + "\"";
                    json += "},";
                }
                if (json.EndsWith(","))
                {
                    json = json.Remove(json.Length - 1);
                }
                json += "]}";
                context.Response.Write(json);
            }
            catch (Exception ex)
            {
                Honestysoft.BaseLibrary.ExceptionHandling.ExceptionHelper.ExceptionDistribute(ex, false);
                Honestysoft.BaseLibrary.Logging.LoggingHelper.WriteLog(ex.Message);
                context.Response.Write("");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}